package com.jichangxiu.server.platform.action;

import com.jichangxiu.common.annotation.Get;
import com.jichangxiu.common.annotation.Rest;
import com.jichangxiu.common.entity.bo.PageData;
import com.jichangxiu.common.utils.ServletUtils;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.server.platform.entity.dto.PlatformLogQueryDto;
import com.jichangxiu.server.platform.entity.vo.PlatformLogQueryVo;
import com.jichangxiu.server.platform.service.PlatformLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * PlatformLogAction:
 * 平台-日志管理控制器
 *
 * @author Jcx
 * @create 2023-02-25 22:10
 */
@Slf4j
@Rest("/platform/log")
@Tag(name = "平台-日志管理控制器")
public class PlatformLogAction extends BaseAction {

    @Resource
    private PlatformLogService platformLogService;

    /**
     * 分页查询日志列表
     *
     * @param platformLogQueryVo 日志视图对象
     * @return 分页日志列表
     */
    @Get(value = "/pageList", logEnabled = false)
    @Operation(summary = "平台-分页查询日志列表")
    @PreAuthorize("@ss.hasPermission('platform:log:pageList')")
    public PageData<PlatformLogQueryDto> pageList(@ParameterObject PlatformLogQueryVo platformLogQueryVo) {
        return platformLogService.pageList(platformLogQueryVo);
    }

    /**
     * 根据ID获取日志详情
     *
     * @param logId 日志ID
     * @return 日志详情
     */
    @Get(value = "/info/{logId}", logEnabled = false)
    @Operation(summary = "平台-根据ID获取日志详情")
    @PreAuthorize("@ss.hasPermission('platform:log:info')")
    public PlatformLogQueryDto info(@PathVariable("logId") @NotBlank(message = "日志ID不能为空") String logId) {
        return platformLogService.info(logId);
    }

}
